//
//  ExtensionTableViewCell.m
//  19_CarHomeWork
//
//  Created by dllo on 16/8/9.
//  Copyright © 2016年 DM.C. All rights reserved.
//

#import "ExtensionTableViewCell.h"
#import "ExtensionCollectionViewCell.h"
#import "ExtensionList.h"
#import "ExtensionResult.h"
#import "Extension.h"
#import "UIImageView+DownloadImage.h"
@interface ExtensionTableViewCell ()<UICollectionViewDelegate, UICollectionViewDataSource>
@property (weak, nonatomic) IBOutlet UICollectionView *extensionCollectionView;
@property (weak, nonatomic) IBOutlet UICollectionViewFlowLayout *layout;
@property (nonatomic, strong) Extension *extension;
@end

@implementation ExtensionTableViewCell

- (void)layoutSubviews {
    [super layoutSubviews];
    CGFloat width = (CGRectGetWidth([UIScreen mainScreen].bounds) - 90)/ 3;
    _layout.itemSize = CGSizeMake(width, self. contentView.frame.size.height - 20);
    _layout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
    self.layout.headerReferenceSize = CGSizeMake(0, 0);
    self.layout.footerReferenceSize = CGSizeMake(0, 0);
    self.extensionCollectionView.frame = [UIScreen mainScreen].bounds;
    _extensionCollectionView.delegate = self;
    _extensionCollectionView.dataSource = self;
//    [self handleData];
    _extensionCollectionView.backgroundColor = [UIColor whiteColor];
    if (_extensionlist) {
        [_extensionCollectionView reloadData];
    }

}
- (void)handleData {
    NSString *path = [[NSBundle mainBundle] pathForResource:@"Extension" ofType:@"json"];
    NSData *pathData = [NSData dataWithContentsOfFile:path];
    NSError *error = nil;
    NSDictionary *extensionCarsDic = [NSJSONSerialization JSONObjectWithData:pathData options:NSJSONReadingMutableContainers error:&error];
    self.extension = [Extension modelWithDic:extensionCarsDic];
    
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    NSLog(@"🐷注视对方减肥的实际得分高级地精发给你京东方%ld", _extensionlist.count);
    return _extensionlist.count;
}
- (__kindof UICollectionViewCell *) collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
        ExtensionCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ExtensionReuse" forIndexPath:indexPath];
    ExtensionList *list = _extensionlist[indexPath.row];
    [cell.extensionImageView asyncDownloadImageWithURL:list.img completionHandler:^(NSData *data, UIImage *image) {
    }];
    
    cell.extensionCarName.text = list.seriesname;
    NSLog(@"🐷注视对方减肥的实际得分高级地精发给你京东方%@", _extensionlist[indexPath.row]);
    return cell;
}







- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
